package app.android.kdictionary.adapter;

import java.util.ArrayList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import app.android.kdictionary.R;
import app.android.kdictionary.data.WordClassData;

// 메뉴 리스트 adapter
public class WordClassAdapter extends BaseAdapter {
	private ArrayList<WordClassData> mData = new ArrayList<WordClassData>();
	
	private LayoutInflater inflater;
	
	public WordClassAdapter(LayoutInflater inflater) {
		this.inflater = inflater;
	}

	public void addItem(final WordClassData item) {
        mData.add(item);
        notifyDataSetChanged();
    }
	
	public void notifyDataSetChanged() {
		super.notifyDataSetChanged();
	}

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public WordClassData getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	WordClassHolder holder = null;
	    if (convertView == null) {
	    	convertView = inflater.inflate(R.layout.multiple_list_02_item, null);
	    	holder = new WordClassHolder();
	    	holder.checkBox = (CheckBox)convertView.findViewById(R.id.multiple_list_02_checkbox);
	    	holder.text = (TextView)convertView.findViewById(R.id.multiple_list_02_text);
	        convertView.setTag(holder);
	    } else {
	        holder = (WordClassHolder)convertView.getTag();
	    }
	    
	    holder.checkBox.setChecked(mData.get(position).isCheck());
	    holder.text.setText(mData.get(position).getText());
	    return convertView;
    }
}

